//
//  GuideTableViewCell.m
//  项目一
//
//  Created by 王鑫 on 15/11/13.
//  Copyright (c) 2015年 王鑫. All rights reserved.
//

#import "GuideTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "GuideModel.h"
#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

@implementation GuideTableViewCell
#pragma mark - Method dealloc
- (void)dealloc {
    [_photoImageView release];
    [_timeLabel release];
    [_titleLabel release];
    [_reviewLabel release];
    [super dealloc];
}
#pragma mark - Method init
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createData];
    }
    return self;
}
#pragma mark - Method createData
- (void)createData {
    self.photoImageView = [[UIImageView alloc] init];
//    self.photoImageView.backgroundColor = [UIColor blueColor];
    [self.contentView addSubview:self.photoImageView];
    [_photoImageView release];
    
    self.timeLabel = [[UILabel alloc] init];
//    self.timeLabel.layer.borderWidth = 1;
//    self.timeLabel.backgroundColor = [UIColor yellowColor];
    self.timeLabel.font = [UIFont systemFontOfSize:10];
    [self.contentView addSubview:self.timeLabel];
    [_timeLabel release];
    
    self.titleLabel = [[UILabel alloc] init];
//    self.titleLabel.layer.borderWidth = 1;
//    self.titleLabel.backgroundColor = [UIColor magentaColor];
    [self.contentView addSubview:self.titleLabel];
    self.titleLabel.font = [UIFont systemFontOfSize:16];
    self.titleLabel.numberOfLines = 0;
    [self.titleLabel sizeToFit];
    [_titleLabel release];
    
    self.reviewLabel = [[UILabel alloc] init];
//    self.reviewLabel.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.reviewLabel];
    self.reviewLabel.font = [UIFont systemFontOfSize:10];
    self.reviewLabel.textAlignment = NSTextAlignmentRight;
    [_reviewLabel release];
}
#pragma mark - Method layoutSubviews
- (void)layoutSubviews {
    [super layoutSubviews];
    self.photoImageView.frame = CGRectMake(10, 10, WIDTH / 3, HEIGHT - 20);
    self.titleLabel.frame = CGRectMake(WIDTH / 3 + 15, 15, WIDTH / 3 * 2  - 15, HEIGHT / 2);
    self.timeLabel.frame = CGRectMake(WIDTH / 3 + 15, HEIGHT / 3 * 2, WIDTH / 3 - 10, HEIGHT / 3);
    self.reviewLabel.frame = CGRectMake(WIDTH / 3 * 2 + 5, HEIGHT / 3 * 2, WIDTH / 3 - 10, HEIGHT / 3);
}
#pragma mark - Method 
- (void)setModel:(GuideModel *)model {
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [self.photoImageView sd_setImageWithURL:[NSURL URLWithString:model.smallpic]];
    self.titleLabel.text = model.title;
    self.timeLabel.text = model.time;
    self.reviewLabel.text = [NSString stringWithFormat:@"%@%@", model.replycount, @"评论"];
}
#pragma mark - Mehtod awakeFromNib
- (void)awakeFromNib {
    // Initialization code
}
#pragma mark - Method setSelected
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
